#pragma once

#include <set>
#include <map>
#include "Singleton.h"
#include "HostBase.h"
#include "2000_topic.pb.h"

class TopicHandler
{
public:
    TopicHandler() = default;
    virtual ~TopicHandler() = default;

public:
    static TopicHandler* Instance()
	{
		return CSingleton<TopicHandler>::Instance();
	}

public:
    // 支持网络修改配置
	int ProcessPacket(CHostBase* host, SocketHandler * pHandler, NETInputPacket* inputPkg);
public:
	void ProcSubscrib(CHostBase* host, SocketHandler* pHandler, NETInputPacket* inputPkg);
	void ProcUnSubscrib(CHostBase* host, SocketHandler* pHandler, NETInputPacket* inputPkg);
    // 网络 推送 分发 事件
	void ProcPublish(CHostBase* host, SocketHandler* pHandler, NETInputPacket* inputPkg);

public:
    // 支持流加载配置
    void ReloadJsonConf(const std::string& json_conf);

public:
    // 直接 分发 事件
    void Dispatch(CHostBase* host, topic_proto::Topic& topic);

public:
    void AddServiceIdMod(std::int32_t topic_event, std::int32_t service);
    void RemoveServiceIdMod(std::int32_t topic_event, std::int32_t service);
    const std::set<std::int32_t>& ServiceIdModHit(std::int32_t topic_event);

    void AddServiceUuidMod(std::int32_t topic_event, std::int32_t service);
    void RemoveServiceUuidMod(std::int32_t topic_event, std::int32_t service);
    const std::set<std::int32_t>& ServiceUuidModHit(std::int32_t topic_event);

    void AddServiceRandom(std::int32_t topic_event, std::int32_t service);
    void RemoveServiceRandom(std::int32_t topic_event, std::int32_t service);
    const std::set<std::int32_t>& ServiceRandomHit(std::int32_t topic_event);

    void AddServiceAll(std::int32_t topic_event, std::int32_t service);
    void RemoveServiceAll(std::int32_t topic_event, std::int32_t service);
    const std::set<std::int32_t>& ServiceAllHit(std::int32_t topic_event);

    void AddInstance(std::int32_t topic_event, std::int32_t service, std::int32_t instance);
    void RemoveInstance(std::int32_t topic_event, std::int32_t service, std::int32_t instance);
    const std::map<std::int32_t,std::int32_t>& InstanceHit(std::int32_t topic_event);

private:
    std::map<std::int32_t, std::set<std::int32_t>> m_event2serviceidmod;
    std::map<std::int32_t, std::set<std::int32_t>> m_event2serviceuuidmod;
    std::map<std::int32_t, std::set<std::int32_t>> m_event2servicerandom;
    std::map<std::int32_t, std::set<std::int32_t>> m_event2serviceall;
    std::map<std::int32_t, std::map<std::int32_t,std::int32_t>> m_event2instance;
};



















